//#include<iostream>
//#include<vector>
//#include<map>
//using namespace std;
//
//int main()
//{
//	
//	//multimap<int, int> mp = { { 1,1 }, { 1,2 }, { 2,3 } };
//	//cout << mp.find(1)->second;
//	vector<int> v({ 1, 2, 3, 4, 5, 6 });
//	vector<vector<int>> vv(3, v);
//	multimap<int, int> mp;
//	for (auto e : vv)
//	{
//		mp.insert({ e[0], e[1] });
//	}
//	for (auto e : mp)
//	{
//		cout << e.first << " ";
//	}
//	return 0;
//}

#include <iostream>
#include<map>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int count = n / 10;
    int ans = 0;
    int a[n][2];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i][0] >> a[i][1];
    }

    multimap<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        mp.insert({ a[i][0], a[i][1] });
    }

    map<int, int> m;
    for (int i = 0; i < n; i++)
    {
        m[a[i][0]]++;
    }
    vector<int> vbig;
    for (auto e : m)
    {
        if (e.second > count)
        {
            vbig.push_back(e.first);
        }
    }
    vector<vector<int>> vv(vbig.size());
    for (int i = 0; i < vbig.size(); i++)
    {
        for (auto e : mp)
        {
            if (vbig[i] == e.first)
            {
                vv[i].push_back(e.second);
            }
        }
    }
    for (int i = 0; i < vbig.size(); i++)
    {
        int n = m[vbig[i]];
        int a[n] = { 0 };
        for (int j = 0; j < vv[i].size(); j++)
        {
            a[j] = vv[i][j];
        }
        int sub = m[vbig[i]] - count;
        while (sub--)
        {
            int min = a[0];
            int mini = 0;
            for (int b = 0; b < vv[i].size(); b++)
            {
                if (a[b] < min)
                {
                    min = a[b];
                    mini = b;
                }
            }
            ans += min;
            a[mini] = 2147483647;
        }
    }

    vector<int> vsmall;
    for (auto e : m)
    {
        if (e.second < count)
        {
            vsmall.push_back(e.first);
        }
    }
    for (size_t i = 0; i < vsmall.size(); i++)
    {
        ans += m[vsmall[i]];
    }
    cout << ans;
    return 0;
}